package org.huzhp.data.handler.pgsql;

import cn.hutool.db.Db;
import cn.hutool.db.DbRuntimeException;
import org.huzhp.data.exception.DataException;
import org.huzhp.data.handler.AbstractHandler;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;

/**
 * @Description: Pgsql
 * @Author: huzp
 * @CreateDate: 2020/4/23 16:17
 * @Version: 1.0
 */
public class PostgresqlHandler extends AbstractHandler{


    @Override
    public Connection connect(DataSource dataSource) {
        try {
            return Db.use(dataSource).getConnection();
        } catch (DbRuntimeException e){
            throw new DataException(e.getMessage(),0001,e.getCause());
        } catch (SQLException e) {
            throw new DataException(e.getMessage(),0001,e.getCause());
        }
    }
}
